package com.ruoyi.web.controller.task;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.task.domain.KwTaskLog;
import com.ruoyi.task.service.IKwTaskLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 监控任务日志Controller
 * 
 * @author gonianer
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/task/taskLog")
public class KwTaskLogController extends BaseController
{
    @Autowired
    private IKwTaskLogService kwTaskLogService;

    /**
     * 查询监控任务日志列表
     */
    @PreAuthorize("@ss.hasPermi('task:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(KwTaskLog kwTaskLog)
    {
        //startPage();
        List<KwTaskLog> list = kwTaskLogService.selectKwTaskLogList(kwTaskLog);
        return getDataTable(list);
    }

    /**
     * 导出监控任务日志列表
     */
    @PreAuthorize("@ss.hasPermi('task:task:export')")
    @Log(title = "监控任务日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KwTaskLog kwTaskLog)
    {
        List<KwTaskLog> list = kwTaskLogService.selectKwTaskLogList(kwTaskLog);
        ExcelUtil<KwTaskLog> util = new ExcelUtil<KwTaskLog>(KwTaskLog.class);
        util.exportExcel(response, list, "监控任务日志数据");
    }

    /**
     * 获取监控任务日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(kwTaskLogService.selectKwTaskLogById(id));
    }

    /**
     * 新增监控任务日志
     */
    @PreAuthorize("@ss.hasPermi('task:task:add')")
    @Log(title = "监控任务日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KwTaskLog kwTaskLog)
    {
        return toAjax(kwTaskLogService.insertKwTaskLog(kwTaskLog));
    }

    /**
     * 修改监控任务日志
     */
    @PreAuthorize("@ss.hasPermi('task:task:edit')")
    @Log(title = "监控任务日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KwTaskLog kwTaskLog)
    {
        return toAjax(kwTaskLogService.updateKwTaskLog(kwTaskLog));
    }

    /**
     * 删除监控任务日志
     */
    @PreAuthorize("@ss.hasPermi('task:task:remove')")
    @Log(title = "监控任务日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(kwTaskLogService.deleteKwTaskLogByIds(ids));
    }
}
